package com.cn.pw.business.jdbc;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;

public class DBTest {
	 public static void main(String[] args) { 
         String driver = "com.mysql.jdbc.Driver"; 
         String url = "jdbc:mysql://localhost:3306/yscn"; 
         String user = "root"; 
         String password = "admin"; 
         try { 
              Class.forName(driver); 
              Connection conn = (Connection) DriverManager.getConnection(url, user, password);
              Statement stmt = (Statement) conn.createStatement();
              String query = "select * from user";
              ResultSet rs=stmt.executeQuery(query);
              while(rs.next()){
            	  System.out.println("user name : " +rs.getString("name") );
              }
              if(!conn.isClosed()) 
                   System.out.println("数据库连接成功！"); 
              conn.close(); 
         } 
         catch(ClassNotFoundException e) { 
              System.out.println("找不到驱动程序"); 
              e.printStackTrace(); 
         } 
         catch(SQLException e) { 
              e.printStackTrace(); 
         } 
    }
}
